package poubelle;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.kramaframework.event.TEventListener;
import org.kramaframework.listener.TMouseListener;

import poubelle.css.CSSLink;
import poubelle.css.CSSTemplate;
import poubelle.html.THTML;
import poubelle.html.child.HTMLLabel;
import poubelle.html.child.HTMLLink;



public class TLink  {

	private String color;
	private String text;
	private String size;
	private String html;
	private String url;
	private String id;
	private String target;

	private CSSTemplate cssLink = new CSSTemplate();
	private HTMLLink htmlLink = new HTMLLink();

	private TImages image;

	private String parentName;

	private List<TEventListener> listenerList = new ArrayList<TEventListener>();

	private String name;

	public void setImage(TImages image) {
		image.setParentName(name);
		image.draw();
		this.text = image.getHtml();
	}

	public TLink(String name, String id) throws IOException {
		if (name != null) {
			this.name = "krama-" + name;
			htmlLink.setName(this.name);
		}
		if (id != null) {
			this.id = id;
			htmlLink.setId("krama-" + this.id);
		}
	}

	public void setId(String id) {
		if (id != null) {
			this.id = id;
			htmlLink.setId("krama-" + this.id);
		}
	}

	public String getId() {
		return id;
	}

	public String getHtml() {
		return html;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
		cssLink.setColor(color);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
		cssLink.setSize(size);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = "krama-" + name;
		htmlLink.setName(this.name);
	}


	public void draw() {

		this.html = htmlLink.starDraw();
		this.html += text;
		this.html += htmlLink.endDraw();
	}

	public void addTMouseListener(TMouseListener mouseListener, String id)
			throws IllegalArgumentException {

		//mouseListener.onClick();
		/*
		if (Ajax.function != null) {
			listenerList.add(mouseListener);
			String fonction = Ajax.function;
			fonction += ", 'krama-" + id + "'";
			htmlLink.addClick(fonction);
			Ajax.function = null;
		}*/
	}

	public CSSTemplate getCssLink() {
		return cssLink;
	}

	public void setCssLink(CSSTemplate cssLink) {
		this.cssLink = cssLink;
	}

	public HTMLLink getHtmlLink() {
		return htmlLink;
	}

	public void setHtmlLink(HTMLLink htmlLink) {
		this.htmlLink = htmlLink;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	
	public String getCSS() {
		return cssLink.getCSS("." + parentName + " ." + name);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
		htmlLink.setUrl(this.url);
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
		htmlLink.setTarget(target);
	}
}
